package com.guang.study.kafka;

import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;

@Configuration
public class KafkaConfig {
    /*@Bean
    KafkaProperties kafkaProperties() {
        return new KafkaProperties();
    }*/

    @Bean
    public KafkaTemplate<String, String> kafkaTemplate(KafkaProperties kafkaProperties) {
        // buildProducerProperties只将生产者的配置设置到了factory
        DefaultKafkaProducerFactory<String, String> factory =
                new DefaultKafkaProducerFactory<>(kafkaProperties.buildProducerProperties());
        return new KafkaTemplate<>(factory);
    }
}
